package com.itheima.grammar.type;

/**
 * @author Anomaly
 * @date 2022/11/28 17:05
 */

/**
 * 数据类型转换
 */
public class Conversion {
    public static void main(String[] args) {
        //赋值（类型范围小的变量可以直接赋值给范围大的变量）
        byte a = 20;
        int b = a;
        System.out.println("b = " + b);
        //表达式自动类型转换
        char c = 'a';
        short d = 20;
        double e = 3.5;
        double r = c + d + e;
        System.out.println("r = " + r);
        //强制类型转换
        int a1 = 20;
        byte a2 = (byte) a1;
        System.out.println("a2 = " + a2);
        //保留整数部分
        double b1 = 2.5;
        int b2 = (int) b1;
        System.out.println("b2 = " + b2);
    }
}
